ComponentOne Data Source for Entity Framework
C1.LiveLinq.Indexing Namespace / ScannerCollection<T> Class / Add Method / Add<TKey>(Expression<Func<T,TKey>>,Boolean,Boolean) Method
The type of the index key.
Key selector expression of the index, see KeySelector.
Specifies whether the key used in this index is a unique key for the indexed collection (default: false).
Specifies whether it is required that the index does not exist prior to this method call (default: false). If an index with this keySelector already exists, an exception is thrown if it is true, and this method call is ignored if it is false.

In This Topic
    Add<TKey>(Expression<Func<T,TKey>>,Boolean,Boolean) Method
    In This Topic
    Creates a new index and adds it to the collection of indexes.
    Syntax
    'Declaration
     
    
    Public Overloads Function Add(Of TKey)( _
       ByVal keySelector As System.Linq.Expressions.Expression(Of Func(Of T,TKey)), _
       ByVal keyIsUnique As System.Boolean, _
       ByVal onlyOnce As System.Boolean _
    ) As IIndexScanner(Of T,TKey)
    public IIndexScanner<T,TKey> Add<TKey>( 
       System.Linq.Expressions.Expression<Func<T,TKey>> keySelector,
       System.bool keyIsUnique,
       System.bool onlyOnce
    )

    Parameters

    keySelector
    Key selector expression of the index, see KeySelector.
    keyIsUnique
    Specifies whether the key used in this index is a unique key for the indexed collection (default: false).
    onlyOnce
    Specifies whether it is required that the index does not exist prior to this method call (default: false). If an index with this keySelector already exists, an exception is thrown if it is true, and this method call is ignored if it is false.

    Type Parameters

    TKey
    The type of the index key.

    Return Value

    The new index added to the collection of indexes.
    Remarks

    A unique index occupies less memory and performs better than a non-unique index (although the difference isn't dramatic). Therefore, for unique keys, it's recommended to specify the corresponding index as unique.

    But do that only if you are sure that the key is indeed unique, as it imposes a uniqueness constraint on the indexed collection. An attempt to modify the indexed collection violating the uniqueness throws an System.InvalidOperationException.

    See Also